<template>
  <ele-modal
    :width="750"
    :visible="visible"
    :confirm-loading="loading"
    title="添加应收款"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <a-form
      :label-col="{ md: { span: 7 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="20" :sm="24" :xs="24">
          <a-form-item label="收款金额">
            <a-input
              placeholder="请输入"
              allow-clear
              v-model:value="form.amount"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form } from 'ant-design-vue';
  import { emailReg, phoneReg, identityReg } from 'ele-admin-pro';
  import { get_collect_amount } from '@/api/jewelry/receipts_return';

  // 表格列配置
  const useForm = Form.useForm;

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    // 编辑数据id
    editData: Object,
    detail: String,
    over: Function
  });

  const emit = defineEmits(['done', 'update:visible']);

  // 提交状态
  const loading = ref(false);

  // 表单数据
  const form = reactive({
    code: '',
    amount: ''
  });

  onMounted(() => {
    form.code = props.editData.code;
    if (form.code) {
      get_collect_amount({ code: form.code }).then((res) => {
        form.amount = res.data;
      });
    }
  });
  // 表单验证规则
  const rules = reactive({});

  const { validate, validateInfos } = useForm(form, rules);
  /* 保存编辑 */
  const save = () => {
    validate()
      .then(() => {
        //console.log("form", form);
        if (props.detail && props.detail == 'detail') {
          //详情页引入时
          props.over(form);
        } else {
          //列表页引入时
          emit('done', form);
        }
        updateVisible(false);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
